<?php defined("MAIN_DIR") or die("No direct access");

$banner_id = UV::readInt($route->getPath(5));

$errors = array();
if ($route->POST('action') == "edit")
{
	$code = UV::readMQ($route->POST('code'));
	$power = $route->POST('power');
	$before = strtotime($route->POST('before'));
	$query = "update `banners` set `code`='$code',`power`='$power',`before`='$before' where `banner_id` = '$banner_id' limit 1";
	if (!$db->sendQuery($query))
		$errors[] = "Не удалось отредактировать";
}

$banner = $db->getRow("select * from `banners` where `banner_id` = '$banner_id' limit 1");
if (!$banner) {
	to("/admin/site/text/");
}

require_once ADMIN.HEADFILE;
?>
<div align="left">
<h1>Редактирование Баннера</h1>
<hr /><?php
if (count($errors) > 0) {
	echo "<p style='color:red'>".implode("<br />",$errors)."</p>";
} elseif ($route->POST('action') == "edit") {
	echo "<p style='color:green'>Успешно отредактировано</p>";
}
?><form method='POST'>
<input type='hidden' name='action' value='edit' />
<table cellpadding='5' cellspacing='0'>
	<tr>
		<td width="100px">Положение</td>
		<td width="500px">
			<input style="width:200px" value='<?php if ($banner['position'] == 'top') echo "В шапке"; else echo "На главной"; ?>' disabled='disabled' />
		</td>
	</tr>
	<tr>
		<td>Включен</td>
		<td>
			<input type='radio' name='power' value='on' <?php if ($banner['power'] != 'off') echo "checked='checked'"; ?> /> Да
			<input type='radio' name='power' value='off' <?php if ($banner['power'] == 'off') echo "checked='checked'"; ?> /> Нет
		</td>
	</tr>
	<tr valign='top'>
		<td>До</td>
		<td><input type='text' style='width:200px' name='before' value='<?php echo date("d.m.Y",$banner['before']); ?>' /></td>
	</tr>
	<tr valign='top'>
		<td>Код</td>
		<td><textarea name='code' style='width:500px;height:150px'><?php echo $banner['code']; ?></textarea></td>
	</tr>
	<tr valign='top'>
		<td colspan='2' align="right"><button style="width:100px;height:30px" type="submit">Сохранить</button></td>
	</tr>
</table>
</form>
<br /><hr /><br />
</div>

<?php require_once ADMIN.FOOTERFILE; ?>